package com.zgh.util;

import com.zgh.usercenter.module.LabourUnion;
import com.zgh.usercenter.module.LabourUnionAndCompany;
import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.Model;

import java.util.List;

/**
 * 工会信息基础设置公用类
 */
public class LabourUnionUtil {

    /**
     * 设置工会女职工人数等信息显示值
     * @param labourUnion
     * @param model
     * @return
     */
    public static Model setLabourUnionShow(LabourUnion labourUnion, Model model){
        if (labourUnion!=null){
            //经审会委员人数
            Integer feeCheckNum=0;
            if (StringUtils.isNotBlank(labourUnion.getFeeCheckMembers())){
                String[] feeCheckMembers=labourUnion.getFeeCheckMembers().split(",");
                feeCheckNum=feeCheckMembers.length;
                if (",".equals(labourUnion.getFeeCheckMembers().substring(labourUnion.getFeeCheckMembers().length()-1,labourUnion.getFeeCheckMembers().length()))){
                    labourUnion.setFeeCheckMembers(labourUnion.getFeeCheckMembers().substring(0,labourUnion.getFeeCheckMembers().length()-1));
                }
            }
            model.addAttribute("feeCheckNum",feeCheckNum);
            //女职工人数
            Integer createWomenNum=0;
            if (StringUtils.isNotBlank(labourUnion.getWomenMembers())){
                String[] womenMembers=labourUnion.getWomenMembers().split(",");
                createWomenNum=womenMembers.length;
                String n=labourUnion.getWomenMembers().substring(labourUnion.getWomenMembers().length()-1,labourUnion.getWomenMembers().length());
                if (",".equals(n)){
                    labourUnion.setWomenMembers(labourUnion.getWomenMembers().substring(0,labourUnion.getWomenMembers().length()-1));
                }
            }
            model.addAttribute("createWomenNum",createWomenNum);
            //经委会名单staffMembers
            Integer staffNum=0;
            if (StringUtils.isNotBlank(labourUnion.getStaffMembers())){
                String[] staffMembers=labourUnion.getStaffMembers().split(",");
                staffNum=staffMembers.length;
                if (",".equals(labourUnion.getStaffMembers().substring(labourUnion.getStaffMembers().length()-1,labourUnion.getStaffMembers().length()))){
                    labourUnion.setStaffMembers(labourUnion.getStaffMembers().substring(0,labourUnion.getStaffMembers().length()-1));
                }
            }
            model.addAttribute("staffNum",staffNum);
            //劳动委员会名单labourLawMembers
            Integer labourLawNum=0;
            if (StringUtils.isNotBlank(labourUnion.getLabourLawMembers())){
                String[] labourLawMembers=labourUnion.getLabourLawMembers().split(",");
                labourLawNum=labourLawMembers.length;
                if (",".equals(labourUnion.getLabourLawMembers().substring(labourUnion.getLabourLawMembers().length()-1,labourUnion.getLabourLawMembers().length()))){
                    labourUnion.setLabourLawMembers(labourUnion.getLabourLawMembers().substring(0,labourUnion.getLabourLawMembers().length()-1));
                }
            }
            model.addAttribute("labourLawNum",labourLawNum);
        }
        return model;
    }

    /**
     * 获取工会下所有公司名称
     * @param listLabourUnionAndCompany
     * @return
     */
    public static String getlistLabourUnionAndCompanyName(List<LabourUnionAndCompany> listLabourUnionAndCompany){
     String companNames="";
     if (!listLabourUnionAndCompany.isEmpty()&&listLabourUnionAndCompany.size()>0){
         for(LabourUnionAndCompany labourUnionAndCompany:listLabourUnionAndCompany){
            if (StringUtils.isNotBlank(labourUnionAndCompany.getCompanyName())){
                companNames+=labourUnionAndCompany.getCompanyName()+",";
            }
         }
     }
     if (StringUtils.isNotBlank(companNames)){
         companNames=companNames.substring(0,companNames.length()-1);
     }
      return companNames;
    }

    /**
     * 获取工会下所有公司的编号
     * @param listLabourUnionAndCompany
     * @return
     */
    public static String getlistLabourUnionAndCompanyCode(List<LabourUnionAndCompany> listLabourUnionAndCompany){
        String companyCodes="";
        if (!listLabourUnionAndCompany.isEmpty()&&listLabourUnionAndCompany.size()>0){
            for(LabourUnionAndCompany labourUnionAndCompany:listLabourUnionAndCompany){
                if (StringUtils.isNotBlank(labourUnionAndCompany.getCompanyUnifiedCode())){
                    companyCodes+=labourUnionAndCompany.getCompanyUnifiedCode()+",";
                }
            }
        }
        if (StringUtils.isNotBlank(companyCodes)){
            companyCodes=companyCodes.substring(0,companyCodes.length()-1);
        }
        return companyCodes;
    }

}
